<?php

require_once 'conexao.php';

$rg = @$_POST['rg'];
$permissao = @strtoupper(strtr($_POST['permissao'], "áéíóúâêôãõàèìòùç", "ÁÉÍÓÚÂÊÔÃÕÀÈÌÒÙÇ"));
$setor = @$_POST['setor'];
$placa = @$_POST['placa'];
$obs = @strtoupper(strtr($_POST['obs'], "áéíóúâêôãõàèìòùç", "ÁÉÍÓÚÂÊÔÃÕÀÈÌÒÙÇ"));
$data = $_POST['dt_ent'];
$hr = $_POST['hr_ent'];

$data = explode('/', $data);
$data = $data['2'] . "-" . $data['1'] . "-" . $data['0'];

if (empty($rg) or ($setor == '*') or empty($data) or empty($hr)) {
    echo "<script type='text/javascript'>
     alert('Todos campos devem ser preenchidos corretamente.'); document.location.href='\index.php?pagina=agendamento'
     </script> ";
} else {
    $query = "INSERT INTO agendamento (rg, permissao, setor, placa, obs, dt_ent, hr_ent) Values (" . $rg . ",'" . $permissao ."','" . $setor . "','" . $placa . "','" . $obs . "','" . $data . "','" . $hr . "')";
    mysql_query($query);
    echo mysql_error();


   echo "<script type='text/javascript'>
     alert('Cadastrado com sucesso !'); document.location.href='index.php?pagina=grade'
  </script> ";
}
?>
